DATABASE

MongoDB use DATABASE_NAME is used to create database. The command will create a new database if it doesn't exist, otherwise it will return the existing database.

use Database_Name

To check your currently selected database, use the command db

If you want to check your databases list, use the command show dbs.



Your created database (mydb) is not present in list. To display database, you need to insert at least one document into it..
db.movie.insert({"name":"XYZ"})
show dbs

Drop Database
The dropDatabase() Method
MongoDB db.dropDatabase() command is used to drop a existing database. This will delete the selected database. If you have not selected any database, then it will delete default 'test' database.

First, check the list of available databases by using the command, show dbs.
>show dbs
local      0.78125GB
mydb       0.23012GB
test       0.23012GB

>use mydb
switched to db mydb
>db.dropDatabase()
>{ "dropped" : "mydb", "ok" : 1 }

Now check list of databases.
>show dbs
local      0.78125GB
test       0.23012GB

No comments:

Post a Comment